<template>
  <div class="newsinfo">
    <h1>{{newsinfo.title}}</h1>
    <p class="subtitle">
      <span>发表时间：{{newsinfo.add_time}}</span>
      <span>阅读量：{{newsinfo.click}}</span>
    </p>
    <hr>
    <div class="content" v-html="newsinfo.content"></div>

    <comment :id="id"></comment>
  </div>
</template>
<script>
import comment from "../../components/subcomponents/comment";
import { Toast } from "vant";
export default {
  data() {
    return {
      newsinfo: {},
      id: this.$route.params.id // 将 URL 地址中传递过来的 Id值，挂载到 data上，方便以后调用
    };
  },
  created() {
    this.getnew();
  },
  components: {
    comment,
  },
  methods: {
    async getnew() {
      const {
        data: { status, message }
      } = await this.$http.get("api/getnew/" + this.id);
      if (status == 0) {
        this.newsinfo = message;
      } else {
        Toast("请求失败");
      }
    }
  }
};
</script>
<style lang="less">
.newsinfo {
  padding: 0 4px;
  h1 {
    font-size: 18px;
    text-align: center;
    margin: 15px 0;
    color: red;
  }
  .subtitle {
    font-size: 13px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
  .content {
    img {
      width: 100%;
    }
  }
}
</style>